<?php
class ListFiles{

	// @param $directory (string) - Pass the directory to go through
	// @param $format (string) - Return files with this extension only (e.g. txt, jpg, pdf)
	
	public function getFiles($directory = '.', $format = FALSE){
		// Initiate an empty array to store results
		$results = array();

		// Open this directory for processing
		$handler = opendir($directory);

		// Read directory contents
		while ($file = readdir($handler)):
			// If this isn't the current directory or
			// the parent directory add it to results array
			echo $this->selfScript();
			if ($file != "." && $file != ".." && $file != $this->selfScript())
				if($format!=FALSE){
					$explode = explode('.', $file);
					$explode = end($explode);
					if(strtolower($explode) == strtolower($format)) $results[] = $file;
				}else{
					$results[] = $file;
				}
		endwhile;

		// Close directory to free up memory
		closedir($handler);

		return $results;

	}
	
	private function selfScript(){
		$self_script = $_SERVER["SCRIPT_NAME"];
		$self_script = Explode('/', $script);
		$self_script = $script[count($script) - 1]; 
		return $self_script;
	}
	
}
?>